"""
该文件用于 扫描界面
"""
import uiautomation as auto
from utils.utils_log import loggerCase
from page.base_page import BasePage
import time


class ScanPage(BasePage):
    """扫描页面"""

    # 激光开始扫描提示
    __start_scan_text = auto.TextControl(Name="Start Scan")

    # 开始中扫描提示
    __scanning_text = auto.TextControl(Name="Scanning")

    # 激光框架点扫描暂停提示
    __markers_scan_pause_text = auto.TextControl(Name="Data Editing/Global Markers Optimization")

    # ========================================右侧栏===============================================
    # 预扫按钮
    __preview_button = auto.ButtonControl(SubName="Preview")

    # 扫描按钮
    __scan_button = auto.GroupControl(SubName="toolBarImg/Scan")

    # 暂停按钮
    __pause_button = auto.GroupControl(SubName="toolBarImg/ScanPause")

    # 方案组
    __project_group = auto.GroupControl(SubName="toolBarImg/sln")

    # 清空数据按钮
    __delete_data_button = auto.GroupControl(SubName="toolBarImg/Delete")

    # 框架点优化
    __optimize_generate_point = auto.GroupControl(SubName="toolBarImg/optimization")

    # ========================================扫描设置===============================================
    # TE Nova
    __te_nova = auto.GroupControl(SubName="access_TE Nova")

    # UE Nova
    __ue_nova = auto.GroupControl(SubName="access_UE Nova")

    # scan mesh扫描
    __scan_mesh_button = auto.GroupControl(SubName="access_Scan Mesh")

    # 局部分辨率
    __partial_resolution = auto.GroupControl(SubName="access_Partial Resolution")

    # 工作距近
    __working_range_near_button = auto.GroupControl(SubName="near")

    # 工作距中
    __working_range_medium_button = auto.GroupControl(SubName="medium")

    # 工作距远
    __working_range_far_button = auto.GroupControl(SubName="far")

    # 新增框架点
    __add_global_markers = auto.GroupControl(SubName="access_Add global markers")

    # 摄影测量扫描
    __photogrammetry_button = auto.GroupControl(SubName="access_Photogrammetry")

    # 标志点尺寸为6mm
    __marker_size_6mm = auto.GroupControl(SubName="access_6mm")

    # 标志点尺寸为12mm
    __marker_size_12mm = auto.GroupControl(SubName="access_12mm")

    # 选择交叉线
    __select_50lines = auto.GroupControl(SubName="line26")

    # 选择7线
    __select_7lines = auto.GroupControl(SubName="line7")

    # 选择1线
    __select_1lines = auto.GroupControl(SubName="line1")

    # 普通物体
    __objectNormal_button = auto.GroupControl(SubName="objectNormal")

    # 反光物体
    __objectReflector_button = auto.GroupControl(SubName="objectBlackReflector")

    # 远距离
    __select_far_button = auto.GroupControl(SubName="far")

    # 中间距离
    __select_medium_button = auto.GroupControl(SubName="medium")

    # 近距离
    __select_near_button = auto.GroupControl(SubName="near")

    # 导入框架点
    __open_global_markers_files = auto.ButtonControl(SubName="access_Open global markers file")

    # 模型质量色谱按钮
    __data_quality_indicator_switch = auto.GroupControl(SubName="access_Data Quality Indicator").GroupControl(SubName="access_Sn3DSwitchButtonClicked")

    # 局部放大按钮
    __local_enlarged_view_switch = auto.GroupControl(SubName="access_Local Enlarged View").GroupControl(SubName="access_Sn3DSwitchButtonClicked")

    # 视觉锁定按钮
    __view_lock_switch = auto.GroupControl(SubName="access_View Lock").GroupControl(SubName="access_Sn3DSwitchButtonClicked")

    # 局部视野
    __tracking_volume_switch = auto.GroupControl(SubName="access_Tracking Volume").GroupControl(SubName="access_Sn3DSwitchButtonClicked")

    # 智能分辨率
    __intelligent_resolution_switch = auto.GroupControl(SubName="access_Intelligent Resolution").GroupControl(SubName="access_Sn3DSwitchButtonClicked")

    def is_has_start_scan_text(self, max_wait_time=5):
        """是否有开始扫描文本"""
        loggerCase.info("是否有开始扫描文本")
        return self.judge_element_exist(ScanPage.__start_scan_text, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1)

    def is_has_scanning_text(self, max_wait_time=5):
        """是否有扫描中文本"""
        loggerCase.info("是否有扫描中文本")
        return self.judge_element_exist(ScanPage.__scanning_text, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1)

    def is_has_markers_scan_pause_text(self, max_wait_time=5):
        """是否有标志点扫描暂停文本"""
        loggerCase.info("是否有标志点扫描暂停文本")
        return self.judge_element_exist(ScanPage.__markers_scan_pause_text, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1)

    def click_te_nova(self, max_wait_time=3):
        """点击TE_Nova按钮"""
        loggerCase.info("点击TE_Nova按钮")
        self.click(ScanPage.__te_nova, max_wait_time=max_wait_time)

    def click_ue_nova(self, max_wait_time=3):
        """点击UE_Nova按钮"""
        loggerCase.info("点击UE_Nova按钮")
        self.click(ScanPage.__ue_nova, max_wait_time=max_wait_time)

    def click_50lines_button(self, max_wait_time=3):
        """点击50线按钮"""
        loggerCase.info("点击50线按钮")
        self.click(ScanPage.__select_50lines, max_wait_time=max_wait_time)

    def click_7lines_button(self, max_wait_time=3):
        """点击7线按钮"""
        loggerCase.info("点击7线按钮")
        self.click(ScanPage.__select_7lines, max_wait_time=max_wait_time)

    def click_1lines_button(self, max_wait_time=3):
        """点击1线按钮"""
        loggerCase.info("点击1线按钮")
        self.click(ScanPage.__select_1lines, max_wait_time=max_wait_time)

    def click_object_normal_button(self, max_wait_time=3):
        """点击普通物体按钮"""
        loggerCase.info("点击普通物体按钮")
        self.click(ScanPage.__objectNormal_button, max_wait_time=max_wait_time)

    def click_object_reflector_button(self, max_wait_time=3):
        """点击反光物体按钮"""
        loggerCase.info("点击反光物体按钮")
        self.click(ScanPage.__objectReflector_button, max_wait_time=max_wait_time)

    def click_far_button(self, max_wait_time=3):
        """点击远距离按钮"""
        loggerCase.info("点击远距离按钮")
        self.click(ScanPage.__select_far_button, max_wait_time=max_wait_time)
        if self.is_has_apply_button():
           self.click_apply_button()

    def click_medium_button(self, max_wait_time=3):
        """点击中间距离按钮"""
        loggerCase.info("点击中间距离按钮")
        self.click(ScanPage.__select_medium_button, max_wait_time=max_wait_time)
        self.loading()

    def click_near_button(self, max_wait_time=3):
        """点击近距离按钮"""
        loggerCase.info("点击近距离按钮")
        self.click(ScanPage.__select_near_button, max_wait_time=max_wait_time)

    def click_photogrammetry_button(self, max_wait_time=3):
        """点击photogrammetry按钮"""
        loggerCase.info("点击点击photogrammetry按钮按钮")
        self.click(ScanPage.__photogrammetry_button, max_wait_time=max_wait_time)
        self.loading()

    def click_marker_size_6mm(self, max_wait_time=3):
        """点击标志点尺寸6mm按钮"""
        loggerCase.info("点击标志点尺寸6mm按钮")
        self.click(ScanPage.__marker_size_6mm, max_wait_time=max_wait_time)

    def click_marker_size_12mm(self, max_wait_time=3):
        """点击标志点尺寸12mm按钮"""
        loggerCase.info("点击标志点尺寸12mm按钮")
        self.click(ScanPage.__marker_size_12mm, max_wait_time=max_wait_time)

    def click_scan_button(self, max_wait_time=5):
        """点击开始扫描按钮"""
        loggerCase.info("点击扫描按钮")
        self.click(ScanPage.__scan_button, max_wait_time=max_wait_time)

    def click_preview_button(self, max_wait_time=3):
        """点击预扫按钮"""
        loggerCase.info("点击预览按钮")
        self.click(self.__preview_button, max_wait_time=max_wait_time)

    def click_pause_scan_button(self, max_wait_time=3):
        """点击暂停扫描按钮"""
        loggerCase.info("点击暂停扫描按钮")
        self.click(ScanPage.__pause_button, max_wait_time=max_wait_time)
        self.loading()

    def click_scan_mesh_button(self, max_wait_time=5):
        """点击扫描网格按钮"""
        loggerCase.info("点击扫描网格按钮")
        self.click(ScanPage.__scan_mesh_button, max_wait_time=max_wait_time)
        self.loading()
    
    def click_partial_resolution(self, max_wait_time=5):
        """局部分辨率"""
        loggerCase.info("点击局部分辨率")
        self.click(ScanPage.__partial_resolution, max_wait_time=max_wait_time)
        self.loading()

    def click_working_range_near_button(self, max_wait_time=5):
        """点击工作距近按钮"""
        loggerCase.info("点击工作距近按钮")
        self.click(ScanPage.__working_range_near_button, max_wait_time=max_wait_time)

    def click_working_range_medium_button(self, max_wait_time=5):
        """点击工作距中按钮"""
        loggerCase.info("点击工作距中按钮")
        self.click(ScanPage.__working_range_medium_button, max_wait_time=max_wait_time)

    def click_working_range_far_button(self, max_wait_time=5):
        """点击工作距远按钮"""
        loggerCase.info("点击工作距中按钮")
        self.click(ScanPage.__working_range_far_button, max_wait_time=max_wait_time)

    def click_add_global_markers(self, max_wait_time=5):
        """点击新增框架按钮"""
        loggerCase.info("点击新增框架按钮")
        self.click(ScanPage.__add_global_markers, max_wait_time=max_wait_time)

    def click_optimize_generate_point(self, max_wait_time=3):
        """点击框架点优化"""
        loggerCase.info("点击框架点优化")
        self.click(ScanPage.__optimize_generate_point, max_wait_time=max_wait_time)
        self.loading()

    def click_project_group(self, max_wait_time=3):
        """方案组"""
        loggerCase.info("点击优化生成点云")
        self.click(ScanPage.__project_group, max_wait_time=max_wait_time)
        self.loading()

    def click_delete_data_button(self, max_wait_time=5):
        """点击清空数据"""
        loggerCase.info("点击清空数据")
        self.click(ScanPage.__delete_data_button, max_wait_time=max_wait_time)

    def click_open_global_markers_file_button(self, max_wait_time=2):
        """点击导入框架的文件按钮"""
        loggerCase.info("点击导入框架的文件按钮")
        self.click(ScanPage.__open_global_markers_files, max_wait_time=max_wait_time)

    def click_data_quality_indicator_switch(self, status='open'):
        """点击模型质量色谱"""
        loggerCase.info("点击模型质量色谱")
        if status == 'open':
            if not self.judge_element_is_Checked(self.__data_quality_indicator_switch):
                self.click(self.__data_quality_indicator_switch)
        if status == 'close':
            if self.judge_element_is_Checked(self.__data_quality_indicator_switch):
                self.click(self.__data_quality_indicator_switch)

    def click_view_lock_switch(self, status='open'):
        """点击视觉锁定"""
        loggerCase.info("点击视觉锁定")
        if status == 'open':
            if not self.judge_element_is_Checked(self.__view_lock_switch):
                self.click(self.__view_lock_switch)

        if status == 'close':
            if self.judge_element_is_Checked(self.__view_lock_switch):
                self.click(self.__view_lock_switch)

    def click_local_enlarged_view_switch(self, status='open'):
        """点击局部放大"""
        loggerCase.info("点击扫物局部放大")
        if status == 'open':
            if not self.judge_element_is_Checked(self.__local_enlarged_view_switch):
                self.click(self.__local_enlarged_view_switch)

        if status == 'close':
            if self.judge_element_is_Checked(self.__local_enlarged_view_switch):
                self.click(self.__local_enlarged_view_switch)

    def click_tracking_volume_switch(self, status='open'):
        """点击局部视野"""
        loggerCase.info("点击局部视野")
        if status == 'open':
            if not self.judge_element_is_Checked(self.__tracking_volume_switch):
                self.click(self.__tracking_volume_switch)

        if status == 'close':
            if self.judge_element_is_Checked(self.__tracking_volume_switch):
                self.click(self.__tracking_volume_switch)

    def click_intelligent_resolution_switch(self, status='open'):
        """点击智能分辨率"""
        loggerCase.info("点击智能分辨率")
        if status == 'open':
            if not self.judge_element_is_Checked(self.__intelligent_resolution_switch):
                self.click(self.__intelligent_resolution_switch)

        if status == 'close':
            if self.judge_element_is_Checked(self.__intelligent_resolution_switch):
                self.click(self.__intelligent_resolution_switch)
